<template>
	<view style=" padding:30rpx">
		<view>异步接口</view>
		<button @click="callStorageFun(1)">setStorage</button>
		<button @click="callStorageFun(2)" type="primary">getStorage</button>
		<button @click="callStorageFun(3)" type="primary">getStorageInfo</button>
		<button @click="callStorageFun(4)" type="warn">RemoveStorage</button>
		<button @click="callStorageFun(5)" type="warn">clearStorage</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name: "ld"
			}
		},
		methods: {
			callStorageFun(parm) {
				console.log("callStorageFun==> parm "+parm);
				switch(parm){
					case 1:
					// 存某一个字段到本地 字段名：值
					uni.setStorage({
						key:'UserName',
						data:'wht',
						success(){
							console.log("UserName 存储成功");
						}
					});
					console.log("调用存储完成");
					break;
					case 2:
					uni.getStorage({
						key:'UserName',
						// 回调接口
						success:function(result){
							console.log("读取成功");
						},
						fail() {
							console.error("读取失败");
						}
					});
					break;
					// case 3:
					// uni.getStorageInfo({
					// 	success:function(result){
							
					// 	}
					// })
				}
			}
		}
	}
</script>

<style>
	button {
		margin: 20rpx;
	}
</style>